# Replication File for
# "Behavioral Consequences of Open Candidate Recruitment"
# Authors: Jochen Rehmert


setwd('...')

 
library(foreign);library(sandwich);library(lmtest) 


dat <- read.dta("volatility.dta")

dat <- dat[dat$year >= 1996,]

kobo.parties <- unique(dat$party_en[dat$kobo == 1])
kobo.parties <- kobo.parties[-which(kobo.parties == "Independent" | kobo.parties == "LDPI")]

###############################################################################
#                             Table A17                                       #
###############################################################################

summary(mod <- glm(kobo ~ as.factor(party_en) + as.factor(year) + enc_t0+ volatility_t0 + district_margin_t0 ,  data = dat[which(dat$party_en %in% kobo.parties & dat$byelection == 0 & dat$year != 2014),], family = binomial(link = "logit")))
 
rows <- row.names(mod$model)
mod.se <- coeftest(mod, vcov = vcovCL(mod, cluster = dat[rows,"kuname"]))[,2]

stargazer(mod, se = list(mod.se), omit = c("party_en","year"),
          covariate.labels = c("Effective Number of Parties$_{t-1}$", "Electoral Volatility$_{t-1}$",
                               "Win Margin$_{t-1}$",
                               "Intercept"))
